﻿#ifndef WRWORKTCPCOMMCLIENTSESSION_H
#define WRWORKTCPCOMMCLIENTSESSION_H

#include "../WRWorkSession.h"
#include "../../WRSoft-Utility/Runtime/WRDataPacket.h"
#include <QMutex>

class WRWorkTcpCommClientObject;
class WRWorkTcpCommClientRoutine;

//表示工作TCP通讯客户端会话。
class WRSOFT_WORKING_COMMON_CLASS WRWorkTcpCommClientSession : public WRWorkSession
{
private:
    WRWorkTcpCommClientRoutine* m_owner;
    QMutex m_mutex;
    QList<WRWorkObject*> m_children;
    WRArray<WRWorkTcpCommClientObject*> m_objects;

public:
    //初始化工作TCP通讯客户端会话
    WRWorkTcpCommClientSession(WRWorkTcpCommClientRoutine* owner, int count, const char* buffer);
    //初始化工作TCP通讯客户端会话
    WRWorkTcpCommClientSession(WRWorkTcpCommClientRoutine* owner, WRWorkTcpCommClientSession* before);

    //清理当前对象所占用的相关资源。
    ~WRWorkTcpCommClientSession(void);

    //获取所有者。
    inline WRWorkTcpCommClientRoutine* owner(void) const
    {
        return m_owner;
    }

    //关闭会话。
    inline void shutdown(void)
    {
        QMutexLocker lck(&m_mutex);
        m_owner = 0;
    }

    //获取会话是否有效。
    inline bool effective(void) const
    {
        return m_owner != 0;
    }

    //处理接收到数据。
    void procData(WR32u idx, const unsigned char* buf, int len);
    //发送数据。
    bool sendData(WRDataPacket* packet);
};

#endif // WRWORKTCPCOMMCLIENTSESSION_H
